package com.hb.trade.api.routine.controller.project.notice;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.hb.core.pojo.Attachment;
import com.hb.core.pojo.center.au.dto.OrgDTO;
import com.hb.core.pojo.center.au.dto.UserDTO;
import com.hb.core.pojo.center.au.entity.User;
import com.hb.core.pojo.enums.*;
import com.hb.core.pojo.parent.PageResult;
import com.hb.core.pojo.project.notice.dto.*;
import com.hb.core.pojo.project.notice.entity.TenderInviteEnterprise;
import com.hb.core.pojo.project.notice.vo.NoticeDetailVo;
import com.hb.core.pojo.project.notice.vo.NoticeListVo;
import com.hb.core.pojo.project.proj.entity.AbstractProject;
import com.hb.core.pojo.project.proj.enums.BidWayEnum;
import com.hb.core.pojo.project.section.dto.BidSectionDTO;
import com.hb.trade.api.routine.service.PortalNoticeService;
import com.hb.trade.api.routine.sms.annotation.SmsSend;
import com.hb.trade.api.routine.util.SendNewsUtil;
import com.hb.trade.client.center.NewsCenterClient;
import com.hb.trade.client.center.OrgClient;
import com.hb.trade.client.center.UserClient;
import com.hb.trade.client.project.*;
import fzzn.core.aspose.convert.AsposeConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.fzzn.core.auth.shiro.util.ShiroUtil;
import org.fzzn.core.model.enums.MsgEnum;
import org.fzzn.core.model.msg.Message;
import org.fzzn.core.model.msg.ResponseDto;
import org.fzzn.core.third.sms.service.SmsService;
import org.fzzn.core.util.Enums;
import org.fzzn.core.util.MsgUtil;
import org.fzzn.core.util.ResultUtil;
import org.fzzn.core.web.anno.Version;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * describe:
 * 公告相关的
 *
 * @author zhongdl
 * @date 2021/12/03
 */
@Slf4j
@Version(1.0)
@Api(tags = {"公告相关的"})
@RequestMapping("/{version}")
@RestController
public class ApiNoticeController {

    protected final RedisTemplate redisTemplate;
    protected final NoticeClient noticeClient;
    protected final UserClient userClient;
    protected final SectionClient sectionClient;
    protected final NewsCenterClient newsCenterClient;
    protected final ProjectClient projectClient;
    protected final SmsService smsService;
    protected final BidFileInfoClient bidFileInfoClient;
    protected final TenderInviteEnterpriseClient tenderInviteEnterpriseClient;
    protected final OrgClient orgClient;
    protected final PortalNoticeService portalNoticeService;

    public ApiNoticeController(RedisTemplate redisTemplate, NoticeClient noticeClient,
                               UserClient userClient,
                               SectionClient sectionClient,
                               NewsCenterClient newsCenterClient,
                               ProjectClient projectClient,
                               SmsService smsService,
                               BidFileInfoClient bidFileInfoClient,
                               TenderInviteEnterpriseClient tenderInviteEnterpriseClient,
                               OrgClient orgClient,
                               PortalNoticeService portalNoticeService) {
        this.redisTemplate = redisTemplate;
        this.noticeClient = noticeClient;
        this.userClient = userClient;
        this.sectionClient = sectionClient;
        this.newsCenterClient = newsCenterClient;
        this.projectClient = projectClient;
        this.smsService = smsService;
        this.bidFileInfoClient = bidFileInfoClient;
        this.tenderInviteEnterpriseClient = tenderInviteEnterpriseClient;
        this.orgClient = orgClient;
        this.portalNoticeService = portalNoticeService;
    }

    @ApiOperation(value = "新增最高限价公告", notes = "新增最高限价公告", httpMethod = "POST")
    @PostMapping("/notice/saveLimitPriceNotice")
    public ResponseDto saveLimitPriceNotice(@RequestBody NoticeLimitPriceDTO priceDto) {
        return ResultUtil.msg(noticeClient.saveLimitPriceNotice(priceDto));
    }

    @ApiOperation(value = "最高限价查看", notes = "最高限价查看", httpMethod = "POST")
    @PostMapping("/notice/info/limitPriceNotice")
    public ResponseDto infoLimitPriceNotice(@RequestBody NoticeBidSectionDTO bidSectionDto) {
        return ResultUtil.msg(noticeClient.infoLimitPriceNotice(bidSectionDto));
    }

    @ApiOperation(value = "新增其他公告", notes = "新增其他公告", httpMethod = "POST")
    @PostMapping("/notice/saveOtherNotice")
    public ResponseDto saveOtherNotice(@RequestBody NoticeDTO noticeDto) {
        return ResultUtil.msg(noticeClient.saveOtherNotice(noticeDto));
    }

    @Deprecated
    @ApiOperation(value = "其他公告列表", notes = "其他公告列表", httpMethod = "POST")
    @PostMapping("/notice/info/otherNotice")
    public ResponseDto infoOtherNotice(@RequestBody NoticeDTO noticeDto) {
        return ResultUtil.msg(noticeClient.infoOtherNotice(noticeDto));
    }

    @ApiOperation(value = "其他公告详情", notes = "其他公告详情", httpMethod = "POST")
    @PostMapping("/notice/info/otherNoticeById")
    public ResponseDto otherNoticeById(@RequestBody NoticeDTO noticeDto) {
        return ResultUtil.msg(noticeClient.otherNoticeById(noticeDto.getId()));
    }

    @ApiOperation(value = "根据标段id查询补充邀请信息", notes = "根据标段id查询补充邀请信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sectionId", value = "公告id", dataTypeClass = String.class),
    })
    @PostMapping("/notice/findSupplementInvitationByNoticeId")
    public ResponseDto findSupplementInvitationByNoticeId(@RequestBody NoticeDTO noticeDto) {
        return ResultUtil.msg(noticeClient.findSupplementInvitationByNoticeId(noticeDto.getSectionId()));
    }

    @ApiOperation(value = "发布公告", notes = "发布公告", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noticeId", value = "公告id", dataTypeClass = String.class),
    })
    @PostMapping("/notice/noticeRelease")
    @Deprecated
    public ResponseDto noticeRelease(@RequestBody NoticeDTO notice) {
        return ResultUtil.msg(noticeClient.noticeRelease(notice));
    }

    @ApiOperation(value = "代理机构操作台--公告列表", httpMethod = "POST")
    @PostMapping("/notice/listNoticeBySectionId")
    public ResponseDto listNoticeBySectionId(@RequestBody NoticeListDTO noticeListDTO) {
        Message<List<NoticeListVo>> message = noticeClient.listNoticeBySectionId(noticeListDTO);
        return ResultUtil.msg(message);
    }

    @ApiOperation(value = "代理机构操作台--公告详情", httpMethod = "POST")
    @PostMapping("/notice/noticeDetail")
    public ResponseDto noticeDetail(@RequestBody NoticeDetailDTO noticeDetailDTO) {
        NoticePortalDTO noticePortalDTO = new NoticePortalDTO();
        noticePortalDTO.setId(noticeDetailDTO.getNoticeId());
        // 查询公告详情
        Message<NoticePortalDTO> noticeDetailVoMessage = noticeClient.noticeDetail(noticePortalDTO);
        NoticePortalDTO portalDTO = noticeDetailVoMessage.getData();
        // 组装返回的Vo
        NoticeDetailVo noticeDetailVo = new NoticeDetailVo();
        noticeDetailVo.setDeployName(portalDTO.getOrgName());
        BeanUtil.copyProperties(portalDTO, noticeDetailVo);
        // 查询绑定的标段信息
        NoticeDTO noticeDTO = new NoticeDTO();
        noticeDTO.setId(portalDTO.getId());
        Message<List<BidSectionDTO>> bidSectionList = noticeClient.listNoticeBidSection(noticeDTO);
        noticeDetailVo.setBidSectionDTOList(bidSectionList.getData());

        return ResultUtil.msg(MsgUtil.success(noticeDetailVo));
    }


    // *********************************************************************************
    // *                             notice manage start                               *
    // *********************************************************************************

    /**
     * 新建公告时返回相应的公告信息
     * 接口会返回项目名称, 项目编号, 默认公告标题, 以及首次公告类型值
     *
     * @param notice
     * @return {@link ResponseDto}
     * @update zhaojk
     */
    @ApiOperation(value = "新建公告时返回相应的公告信息", notes = "新建公告时返回相应的公告信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataTypeClass = String.class),
    })
    @PostMapping("/notice/initData")
    public ResponseDto initNoticeData(@RequestBody NoticeDTO notice) {
        if (notice.getProjectId() == null) {
            return ResultUtil.msg(MsgEnum.INCORRECT_PARAM);
        }
        Message<NoticeDTO> noticeInfo = noticeClient.initNoticeData(notice);
        return ResultUtil.msg(noticeInfo);
    }

    /**
     * 保存公告信息
     *
     * @param noticeDTO
     * @return {@link ResponseDto}
     * @update zhaojk
     */
    @ApiOperation(value = "保存公告信息", notes = "保存公告信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noticeDto", value = "接收保存报告的对象", dataTypeClass = NoticeDTO.class),
    })
    @PostMapping("/notice/saveNotice")
    public ResponseDto saveNotice(@RequestBody NoticeDTO noticeDTO) {
        // 基本参数验证
        String addParamsValidMsg = noticeDTO.paramsValid();
        if (StrUtil.isNotEmpty(addParamsValidMsg)) {
            return ResultUtil.fail(addParamsValidMsg);
        }
        // 设置公告所属公司和用户
        ShiroUtil.fillOwner(noticeDTO);
        //设置创建人和更新人
        if (noticeDTO.getId() == null) {
            noticeDTO.setCreateName(ShiroUtil.getUser().getFullName());
        } else {
            noticeDTO.setUpdateName(ShiroUtil.getUser().getFullName());
        }
        if (CollUtil.isNotEmpty(noticeDTO.getContentUrl())) {
            Attachment attachment = noticeDTO.getContentUrl().get(0);
            File thisFile = attachment.getThisFile();
            String htmlStr = AsposeConvertUtil.wordToHtml(thisFile);
            noticeDTO.setNoticeContent(htmlStr);
        }
        Message<NoticeDTO> booleanMessage = noticeClient.saveNotice(noticeDTO);
        if (booleanMessage.isSuccess()) {
            NoticeDTO data = booleanMessage.getData();
            NoticeDTO dataNotice = new NoticeDTO();
            dataNotice.setId(data.getId());
            return ResultUtil.msg(true, dataNotice);
        }
        return ResultUtil.msg(booleanMessage);
    }

    @ApiOperation(value = "保存公告并发布公告信息", notes = "保存公告并发布公告信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noticeDto", value = "接收保存报告的对象", dataTypeClass = NoticeDTO.class),
    })
    @SmsSend(type = 3)
    @PostMapping("/notice/saveNoticeDeploy")
    public ResponseDto saveNoticeDelopy(@RequestBody NoticeDTO noticeDTO) {
        // 基本参数验证
        String addParamsValidMsg = noticeDTO.paramsValid();
        if (StrUtil.isNotEmpty(addParamsValidMsg)) {
            return ResultUtil.fail(addParamsValidMsg);
        }
        //设置创建人和更新人
        if (noticeDTO.getId() == null) {
            noticeDTO.setCreateName(ShiroUtil.getUser().getFullName());
        } else {
            noticeDTO.setUpdateName(ShiroUtil.getUser().getFullName());
        }
        // 设置公告所属公司和用户
        ShiroUtil.fillOwner(noticeDTO);
        if (CollUtil.isNotEmpty(noticeDTO.getContentUrl())) {
            Attachment attachment = noticeDTO.getContentUrl().get(0);
            File thisFile = attachment.getThisFile();
            String htmlStr = AsposeConvertUtil.wordToHtml(thisFile);
            noticeDTO.setNoticeContent(htmlStr);

        }
        Message<NoticeDTO> booleanMessage = noticeClient.saveNotice(noticeDTO);

        Long noticeId = noticeDTO.getId();
        if (noticeId == null) {
            return ResultUtil.msg(MsgEnum.INCORRECT_PARAM);
        }
        noticeDTO.setDeployTime(LocalDateTime.now());
        Message<Boolean> noticeInfo = noticeClient.noticeDeploy(noticeDTO);
        //变更公告/控制价公告/终止公告
        Message<NoticeDTO> noticeDTOMessage = noticeClient.findNoticeInfo(noticeDTO);
        if (noticeDTOMessage.isFail() || noticeDTOMessage.getData() == null) {
            return ResultUtil.msg(noticeInfo);
        }

        for (BidSectionDTO bidSectionDTO : noticeDTO.getBidSectionList()) {
            Long sectionId = bidSectionDTO.getId();
            String key = sectionId + "&" + SmsTypeEnum.OPENING.getCode();
            LocalDateTime openBidTime = null;
            if (noticeDTO.getSectionOptions() != null) {
                openBidTime = noticeDTO.getSectionOptions().getOpenBidTime();
            }
            if (openBidTime != null) {
                long time = Timestamp.valueOf(openBidTime).getTime();
                time = time - System.currentTimeMillis() - (24 * 60 * 60 * 1000);
                // 如果小于24小时 则立即发送短信
                if (time > 0) {
                    redisTemplate.delete(key);
                    redisTemplate.opsForValue().set(key, sectionId.toString(), time, TimeUnit.MILLISECONDS);
                } else {
                    redisTemplate.delete(key);
                    redisTemplate.opsForValue().set(key, sectionId.toString(), 5, TimeUnit.MILLISECONDS);
                }
            }
        }
        Integer noticeNature = noticeDTOMessage.getData().getNoticeNature();

        AbstractProject abstractProject = new AbstractProject();
        abstractProject.setId(noticeDTO.getProjectId());
        abstractProject = projectClient.projectDetail(abstractProject).getData();
        // 如果是公开的或者是单一来源的则需要同步到门户公告
        if (Enums.equals(CommonTypeEnum.OPEN, abstractProject.getCommonType()) || Enums.equals(BidWayEnum.SINGLE, abstractProject.getBidWay())) {
            // 将公告信息同步至门户公告表
            portalNoticeService.pushNoticeToPortal(noticeDTO.getId(), abstractProject);
        }
        //如果邀请的项目给邀请人发送信息
        if (Enums.equals(CommonTypeEnum.INVITE, abstractProject.getCommonType())) {
            TenderInviteEnterpriseDTO tenderInviteEnterpriseDTO = new TenderInviteEnterpriseDTO();
            tenderInviteEnterpriseDTO.setNoticeId(noticeDTO.getId());
            Message<List<TenderInviteEnterprise>> tenderInviteListMsg = tenderInviteEnterpriseClient.findInviteEnterpriseListByNoticeId(tenderInviteEnterpriseDTO);
            if (CollUtil.isEmpty(tenderInviteListMsg.getData())) {
                return ResultUtil.msg(noticeInfo);
            }
            List<TenderInviteEnterprise> data = tenderInviteListMsg.getData();
            //给投标人发送短信
            for (TenderInviteEnterprise tenderInviteEnterprise : data) {
                OrgDTO org = orgClient.getOrgById(Long.valueOf(tenderInviteEnterprise.getOrgId())).getData();
                UserDTO queryParam = new UserDTO();
                queryParam.setOrgId(org.getId());
                List<User> userList = userClient.listUsers(queryParam).getData();
                if (CollUtil.isEmpty(userList)) {
                    continue;
                }
                List<Long> receiverIds = userList.stream().map(User::getId).collect(Collectors.toList());
                //发送消息
                SendNewsUtil.sendBiddereeNews(
                        tenderInviteEnterprise.getSectionId(),
                        NewsTypeEnum.PROJECT_CHANGE,
                        NewsTypeTwoEnum.NOTICE_INVITATION,
                        Enums.nameOf(NoticeNatureEnum.class, noticeNature),
                        null,
                        SendNewsUtil.getNoticeRoute(noticeNature),
                        receiverIds
                );
            }
            return ResultUtil.msg(noticeInfo);
        }
        //给投标人发送消息
        List<BidSectionDTO> bidSectionList = noticeDTOMessage.getData().getBidSectionList();
        if (CollUtil.isEmpty(bidSectionList)) {
            return ResultUtil.msg(noticeInfo);
        }
        //查询参与该标段的投标人
        for (BidSectionDTO bidSectionDTO : bidSectionList) {

            Message<List<Long>> longUserIds = sectionClient.listParticipateSection(bidSectionDTO.getId());
            if (longUserIds.isFail() || CollUtil.isEmpty(longUserIds.getData())) {
                continue;
            }
            List<Long> receiverIds = longUserIds.getData();
            //发送消息
            SendNewsUtil.sendBiddereeNews(
                    bidSectionDTO.getId(),
                    NewsTypeEnum.PROJECT_CHANGE,
                    NewsTypeTwoEnum.NOTICE_PROJECT_CHANGE,
                    Enums.nameOf(NoticeNatureEnum.class, noticeNature),
                    null,
                    SendNewsUtil.getNoticeRoute(noticeNature),
                    receiverIds
            );
        }
        return ResultUtil.msg(noticeInfo);
    }

    /**
     * 查询公告列表信息
     * 指定项目下所有标段关联的公告列表
     * 按创建时间排序
     *
     * @return {@link ResponseDto}
     * @update zhaojk
     */
    @ApiOperation(value = "查询公告列表信息", notes = "查询公告列表信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目ID", dataTypeClass = NoticeDTO.class),
    })
    @PostMapping("/notice/findNoticeList")
    public ResponseDto findNoticeList(@RequestBody NoticeDTO noticeDTO) {
        Long projectId = noticeDTO.getProjectId();
        if (projectId == null) {
            return ResultUtil.msg(MsgEnum.INCORRECT_PARAM);
        }
        ShiroUtil.fillOwner(noticeDTO);
        Message<User> user = userClient.getByUserId(ShiroUtil.getUserId());
        //企业id
        if (user.isSuccess() && user.getData() != null) {
            noticeDTO.setUserType(user.getData().getUserType());
        }
        Message<PageResult<NoticeDTO>> noticeList = noticeClient.findNoticeList(noticeDTO);
        return ResultUtil.msg(noticeList);
    }

    /**
     * @param noticeDTO: 标段
     * @Description: 查询公告页面的信息 (有公告id只查询这个公告的信息,有标段的查询首次公告)
     * @Author: zhongdl
     * @Date:2021/12/8 9:53
     * @return: {@link org.fzzn.core.model.msg.ResponseDto }
     */
    @ApiOperation(value = "查询公告页面的信息", notes = "查询公告页面的信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公告id", dataTypeClass = String.class)

    })
    @PostMapping("/notice/findNoticeInfo")
    public ResponseDto findNoticeInfo(@RequestBody NoticeDTO noticeDTO) {
        Long noticeId = noticeDTO.getId();
        if (noticeId == null) {
            return ResultUtil.msg(MsgEnum.INCORRECT_PARAM);
        }
        Message<NoticeDTO> noticeInfo = noticeClient.findNoticeInfo(noticeDTO);
        return ResultUtil.msg(noticeInfo);
    }

    @ApiOperation(value = "查询公告页的标段列表", notes = "查询公告页面的信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公告id", dataTypeClass = Long.class)
    })
    @PostMapping("/notice/listNoticeBidSection")
    public ResponseDto listNoticeBidSection(@RequestBody NoticeDTO noticeDTO) {
        Long noticeId = noticeDTO.getId();
        if (noticeId == null) {
            return ResultUtil.msg(MsgEnum.INCORRECT_PARAM);
        }
        Message<List<BidSectionDTO>> noticeInfo = noticeClient.listNoticeBidSection(noticeDTO);
        return ResultUtil.msg(noticeInfo);
    }

    /**
     * 发布公告, 修改公告的发布状态
     *
     * @param noticeDTO id 公告ID
     * @return {@link Message}
     * @update zhaojk
     */
    @ApiOperation(value = "发布公告", notes = "修改公告的发布状态", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公告id", dataTypeClass = String.class)
    })
    @SmsSend(type = 3)
    @PostMapping("/notice/deploy")
    public ResponseDto noticeDeploy(@RequestBody NoticeDTO noticeDTO) {
        Long noticeId = noticeDTO.getId();
        if (noticeId == null) {
            return ResultUtil.msg(MsgEnum.INCORRECT_PARAM);
        }
        noticeDTO.setDeployTime(LocalDateTime.now());
        Message<Boolean> noticeInfo = noticeClient.noticeDeploy(noticeDTO);
        //变更公告/控制价公告/终止公告
        Message<NoticeDTO> noticeDTOMessage = noticeClient.findNoticeInfo(noticeDTO);
        if (noticeDTOMessage.isFail() || noticeDTOMessage.getData() == null) {
            return ResultUtil.msg(noticeInfo);
        }

        AbstractProject abstractProject = new AbstractProject();
        abstractProject.setId(noticeDTOMessage.getData().getProjectId());
        abstractProject = projectClient.projectDetail(abstractProject).getData();
        // 如果是公开的或者是单一来源的则需要同步到门户公告
        if (Enums.equals(CommonTypeEnum.OPEN, abstractProject.getCommonType()) || Enums.equals(BidWayEnum.SINGLE, abstractProject.getBidWay())) {
            // 将公告信息同步至门户公告表
            portalNoticeService.pushNoticeToPortal(noticeDTO.getId(), abstractProject);
        }
        //给投标人发送消息
        Integer noticeNature = noticeDTOMessage.getData().getNoticeNature();
        List<BidSectionDTO> bidSectionList = noticeDTOMessage.getData().getBidSectionList();
        if (CollUtil.isEmpty(bidSectionList)) {
            return ResultUtil.msg(noticeInfo);
        }
        //查询参与该标段的投标人
        for (BidSectionDTO bidSectionDTO : bidSectionList) {
            Message<List<Long>> longUserIds = sectionClient.listParticipateSection(bidSectionDTO.getId());
            if (longUserIds.isFail() || CollUtil.isEmpty(longUserIds.getData())) {
                continue;
            }
            List<Long> receiverIds = longUserIds.getData();
            //发送消息
            SendNewsUtil.sendBiddereeNews(
                    bidSectionDTO.getId(),
                    NewsTypeEnum.PROJECT_CHANGE,
                    NewsTypeTwoEnum.NOTICE_PROJECT_CHANGE,
                    Enums.nameOf(NoticeNatureEnum.class, noticeNature),
                    null,
                    SendNewsUtil.getNoticeRoute(noticeNature),
                    receiverIds
            );
        }
        return ResultUtil.msg(noticeInfo);
    }

    /**
     * 查询指定标段关联的所有公告
     *
     * @param noticeDTO id 公告ID
     * @return {@link Message}
     * @update zhaojk
     */
    @ApiOperation(value = "查询指定标段关联的所有公告", notes = "查询指定标段关联的所有公告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sectionId", value = "标段ID", dataTypeClass = Long.class)
    })
    @PostMapping("/notice/pageBySectionId")
    public ResponseDto pageBySectionId(@RequestBody NoticeDTO noticeDTO) {
        Long sectionId = noticeDTO.getSectionId();
        if (sectionId == null) {
            return ResultUtil.msg(MsgEnum.INCORRECT_PARAM);
        }
        Message<PageResult<NoticeDTO>> notices = noticeClient.pageBySectionId(noticeDTO);
        return ResultUtil.msg(notices);
    }

    @ApiOperation(value = "根据项目ID查询公告", notes = "根据项目ID查询公告，主要用于判断项目是否发过公告来决定该项目是否能删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目ID", dataTypeClass = Long.class)
    })
    @PostMapping("/notice/findNoticeByProjectId")
    public ResponseDto findNoticeByProjectId(@RequestBody NoticeDTO noticeDTO) {
        if (noticeDTO == null || noticeDTO.getProjectId() == null) {
            return ResultUtil.fail(MsgEnum.INCORRECT_PARAM_TYPE.msg());
        }
        Message noticeList = this.noticeClient.findNoticeByProjectId(noticeDTO);
        return ResultUtil.msg(noticeList);
    }
}
